package com.example.yy.helloword0001;

import android.app.ActionBar;
import android.support.constraint.ConstraintLayout;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.Toast;

public class MyToolBarActivity extends AppCompatActivity {

    private  Toolbar toolbar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_tool_bar);

        toolbar = findViewById(R.id.mytool);
        setSupportActionBar(toolbar);


        //响应左边按钮点击事件
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MyToolBarActivity.this,"展开",Toast.LENGTH_LONG).show();

            }
        });

        //响应工具栏按钮点击事件
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener(){
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.action_qunliu:
                        Toast.makeText(MyToolBarActivity.this,"群聊",Toast.LENGTH_LONG).show();
                        break;
                    case R.id.action_h:
                        Toast.makeText(MyToolBarActivity.this,"章节",Toast.LENGTH_LONG).show();
                        break;
                    case R.id.action_settings:
                        Toast.makeText(MyToolBarActivity.this,"设置",Toast.LENGTH_LONG).show();
                        break;
                }
                return true;
            }
        });

    }

//    加载工具toolbar菜单
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.base_menu,menu);
        return true;
    }
}
